/** This is a helper class for creating some hashes 
 *  @author Copyright (c) 2005 by chrmac@gmx.de*/

package com.jtalker.client;

import java.security.*;
import java.text.*;

/** Class for creating and checking MD5 hashes */
public class MD5Password {

   //private final static char[] HEX = "0123456789abcdef".toCharArray();
   
   /** Creates a MD5 hash */
   public static String hashPassword(String _password) {
      String hashword = null;
      try {
	 MessageDigest md5 = MessageDigest.getInstance("MD5");
	 md5.update(_password.getBytes());
	 java.math.BigInteger hash = new java.math.BigInteger(1, md5.digest());
	 hashword = hash.toString(16);
	 
	 /*byte[] bytes = md5.digest();
	 StringBuffer sb = new StringBuffer(bytes.length * 2);
         int b;
	 
	 
         for (int i=0; i < bytes.length; i++) {
            b=bytes[i] & 0xFF;
            sb.append(HEX[b >>> 4]);
            sb.append(HEX[b & 0x0F]);
         }

	 hashword = sb.toString();*/
       } catch (NoSuchAlgorithmException nsae) {
	 // ignore
       }
       return hashword;
  }  
}

